package com.edu.medicalpro.RecyclerViewadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.edu.medicalpro.R;
import com.edu.medicalpro.bean.DoctorData;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {
    private Context context;
    private List<DoctorData.DataBean.ListBean> dataList;
    public MyAdapter(Context context) {
        this.context = context;
    }

    public void setDataList(List<DoctorData.DataBean.ListBean> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyHolder holder =new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_doctor,null));
        return holder;
    }
    @Override
    public void onBindViewHolder( MyHolder holder, int position) {
        holder.name.setText((String)dataList.get(position).getDocName());
        holder.icon.setImageResource(R.mipmap.ic_launcher);
        holder.title.setText((String)dataList.get(position).getDocJob());
        holder.test.setText((String)dataList.get(position).getDocSex());
        holder.age.setText((String)dataList.get(position).getDocBirthday());
    }
    @Override
    public int getItemCount() {
        return null==dataList ? 0:dataList.size();
    }
    class MyHolder extends RecyclerView.ViewHolder{
        ImageView icon;
        TextView name;
        TextView title;
        TextView test;
        TextView age;
        public MyHolder( View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.doctor_image);
            name =itemView.findViewById(R.id.doctor_name);
            title =itemView.findViewById(R.id.doctor_keshi);
            test =itemView.findViewById(R.id.doctor_zhicheng);
            age =itemView.findViewById(R.id.doctor_shanchang);

        }
     }
}
